package com.ys.service.sys.impl;

import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.itextpdf.text.*;
import com.itextpdf.text.pdf.PdfPCell;
import com.ys.service.purchase.impl.TcgOfflinePurchaseInStorageServiceImpl;
import com.ys.service.storage.impl.TccOfflineAssembleImpl;
import org.springframework.stereotype.Service;

import com.bo.dto.NameValueDto;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.ys.config.MyConfig;
import com.ys.entity.flow.YspTaskAudit;
import com.ys.entity.flow.YspTaskAuditUser;
import com.ys.entity.shiro.LoginUser;
import com.ys.entity.sys.YsProcInst;
import com.ys.enume.flow.YspTaskAuditEnum;
import com.ys.enume.flow.YspTaskAuditUserEnum;
import com.ys.service.sys.PdfService;
import com.ys.service.sys.PdfService.ListingSubDto;
import com.ys.util.DateUtil;
import com.ys.util.PdfUtil;
import com.ys.util.shiro.ShiroUtils;

@Service("pdfService")
public class PdfServiceImpl implements PdfService {

	// 定义全局的字体静态变量
	private static BaseFont bfChinese = PdfUtil.createFontLocal("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);

	private static Font textfont4 = new Font(bfChinese, 4, Font.NORMAL);
	private static Font textfont6 = new Font(bfChinese, 6, Font.NORMAL);
	private static Font textfont8 = new Font(bfChinese, 8, Font.NORMAL);
	private static Font textfont8W = new Font(bfChinese, 8, Font.BOLD);
	private static Font textfont10 = new Font(bfChinese, 10, Font.NORMAL);
//	private static Font textfont11 = new Font(bfChinese, 11, Font.NORMAL);
	private static Font textfont12 = new Font(bfChinese, 12, Font.NORMAL);
	private static Font textfont14 = new Font(bfChinese, 14, Font.NORMAL);
	private static Font textfont14W = new Font(bfChinese, 14, Font.BOLD);
	private static Font textfont16 = new Font(bfChinese, 16, Font.NORMAL);
	private static Font textfont16Bold = new Font(bfChinese, 16, Font.BOLD);
	private static Font textfont18 = new Font(bfChinese, 18, Font.NORMAL);

	private static Font keyfont;

	@Override
	public String generatePDF(String bid, String title, String companyVname, String timeYYYYMMDDHHmmss, List<NameValueDto> listData) {

		Rectangle rec = new RectangleReadOnly(420, 600);

		try {
			// 1.新建document对象
			Document document = new Document(rec);// 建立一个Document对象
			document.setMargins(0, 0, 15f, 0);
			document.setPageCount(1);//设置生成pdf页数
			// 2.建立一个书写器(Writer)与document对象关联
//			File file = new File("D://data/PDF配货清单.pdf");
			String dir = MyConfig.getProfile();
			String pdfFileName = "/pdf/" + bid + ".pdf";
			File file = new File(dir + pdfFileName);
			file.createNewFile();
			PdfWriter.getInstance(document, new FileOutputStream(file));
			// 3.打开文档
			document.open();

			//4.生成PDF
			document.newPage();
//			document.setPageCount(i);//设置生成pdf页数
			{
				// 表格
				PdfPTable table1;
				PdfPTable table2;
				{
					table1 = PdfUtil.createTable(new float[]{80, 60, 100, 60}, 1, 400);
					table2 = PdfUtil.createTable(new float[]{134, 133, 133}, 1, 400);

					table1.addCell(PdfUtil.createCell(title, textfont14, Element.ALIGN_CENTER, 4, 0));
					table1.addCell(PdfUtil.createCell(companyVname, textfont8, Element.ALIGN_LEFT, 2, 0));
					table1.addCell(PdfUtil.createCell("申请时间：" + timeYYYYMMDDHHmmss, textfont8, Element.ALIGN_RIGHT, 2, 0));

					for(NameValueDto e : listData) {
						table1.addCell(PdfUtil.createCell(e.getName() + "：", textfont8, Element.ALIGN_CENTER, 1));
						table1.addCell(PdfUtil.createCell(e.getValue(), textfont8, Element.ALIGN_CENTER, 4, 1));
					}

					table1.addCell(PdfUtil.createCell("审核明细", textfont8, Element.ALIGN_LEFT, 5, 0));
					{

						table2.addCell(PdfUtil.createCell("处理时间", textfont8, Element.ALIGN_CENTER, 1));
						table2.addCell(PdfUtil.createCell("处理人", textfont8, Element.ALIGN_CENTER, 1));
						table2.addCell(PdfUtil.createCell("处理结果", textfont8, Element.ALIGN_CENTER, 1));
					}

					YsProcInst ysProcInst = new YsProcInst().setBid(bid).queryFirst();
					List<YspTaskAudit> listYspTaskAudit = new YspTaskAudit().setTaskId(ysProcInst.getTaskId()).queryList();
					for(YspTaskAudit row : listYspTaskAudit) {

						// 拼接处理人
						String opeUsers = "";
						List<Map<String, Object>> listYspTaskAuditUser = new YspTaskAuditUser()
								.setTaskId(ysProcInst.getTaskId())
								.setTaskAuditId(row.getId())
								.addLeftJoin("TS_UserInfo B ON B.UserId = A.UserId")
								.addField("B.UserName userName")
								.where("A.State in (" + YspTaskAuditUserEnum.State.FAILED.value + "," + YspTaskAuditUserEnum.State.SUCCESS.value + ")")
								.queryMap();
						for(Map<String, Object> map : listYspTaskAuditUser) {
							opeUsers = opeUsers + map.get("userId") + "/" + map.get("userName") + ",";
						}

						table2.addCell(PdfUtil.createCell(DateUtil.getYYYY_MM_DD_HH_mm_ss(row.getUpdateTime()), textfont8, Element.ALIGN_CENTER, 1));
						table2.addCell(PdfUtil.createCell(opeUsers.equals("")?opeUsers:opeUsers.substring(0, opeUsers.length() - 1), textfont8, Element.ALIGN_CENTER, 1));
						table2.addCell(PdfUtil.createCell(YspTaskAuditEnum.State.getName(row.getState()), textfont8, Element.ALIGN_CENTER, 1));
					}

					{
						LoginUser loginUser = ShiroUtils.getLoginUser();
						String loginUserName = loginUser.getUserName();
						String loginUserUserId = loginUser.getUserId();
						String deptName = loginUser.getOrgName();
//						table2.addCell(PdfUtil.createCell("打印时间：" + DateUtil.getYYYY_MM_DD_HH_mm_ss(new Date()), textfont8, Element.ALIGN_CENTER, 0));
						table2.addCell(PdfUtil.createCell(" ", textfont8, Element.ALIGN_CENTER, 0));
						table2.addCell(PdfUtil.createCell("打印人：" + loginUserUserId + "/" +loginUserName, textfont8, Element.ALIGN_CENTER, 0));
						table2.addCell(PdfUtil.createCell("打印人部门：" + deptName, textfont8, Element.ALIGN_CENTER,  0));
					}
				}
				document.add(table1);
				document.add(table2);

			}

			// 5.关闭文档
			document.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

		return MyConfig.getUrlDomain() + "/upload/pdf/" + bid + ".pdf";
	}

	@Override
	public String generatePDF_XSFP(String companyAllNameCn, String companyAllNameEn, String toCompanyAllNameCn,
			String invoiceNo, String amountTotalCny, String invoiceDate, String originCountry, String vgsbm,
			List<ProductDto> listData) {

		String code = "XS_" + invoiceNo;

		Rectangle rec = new RectangleReadOnly(420, 600);

		try {
			// 1.新建document对象
			Document document = new Document(rec);// 建立一个Document对象
			document.setMargins(0, 0, 15f, 0);
			document.setPageCount(1);//设置生成pdf页数
			// 2.建立一个书写器(Writer)与document对象关联
//			File file = new File("D://data/PDF配货清单.pdf");
			String dir = MyConfig.getProfile();
			String pdfFileName = "/pdf/" + code + ".pdf";
			File file = new File(dir + pdfFileName);
			file.createNewFile();
			PdfWriter.getInstance(document, new FileOutputStream(file));
			// 3.打开文档
			document.open();

			//4.生成PDF
			document.newPage();
//			document.setPageCount(i);//设置生成pdf页数
			{

				// 表格
				PdfPTable table1;
				{
					table1 = PdfUtil.createTable(new float[]{100, 100, 100, 100, 100, 100}, 1, 400);

					table1.addCell(PdfUtil.createCell(companyAllNameCn, textfont14W, Element.ALIGN_CENTER, 6, 1));
					table1.addCell(PdfUtil.createCell(companyAllNameEn, textfont14, Element.ALIGN_CENTER, 6, 1));
					table1.addCell(PdfUtil.createCell("销售发票", textfont14W, Element.ALIGN_CENTER, 6, 1));
					table1.addCell(PdfUtil.createCell("Sales Invoice", textfont14, Element.ALIGN_CENTER, 6, 1));

					table1.addCell(PdfUtil.createCell("TO:", textfont8W, Element.ALIGN_CENTER, 1, 2, 1));
					table1.addCell(PdfUtil.createCell(toCompanyAllNameCn, textfont8, Element.ALIGN_CENTER, 2, 2, 1));
					table1.addCell(PdfUtil.createCell("发票号码", textfont8W, Element.ALIGN_CENTER, 1, 1));
					table1.addCell(PdfUtil.createCell(invoiceNo, textfont8, Element.ALIGN_CENTER, 2, 2, 1));
					table1.addCell(PdfUtil.createCell("Invoice No.", textfont8W, Element.ALIGN_CENTER, 1, 1));

					table1.addCell(PdfUtil.createCell("总金额(CNY)", textfont8W, Element.ALIGN_CENTER, 1, 1, 1));
					table1.addCell(PdfUtil.createCell(amountTotalCny, textfont8, Element.ALIGN_CENTER, 2, 2, 1));
					table1.addCell(PdfUtil.createCell("发票日期", textfont8W, Element.ALIGN_CENTER, 1, 1));
					table1.addCell(PdfUtil.createCell(invoiceDate, textfont8, Element.ALIGN_CENTER, 2, 2, 1));
					table1.addCell(PdfUtil.createCell("Total Amount", textfont8W, Element.ALIGN_CENTER, 1, 1, 1));
					table1.addCell(PdfUtil.createCell("Date of Invoice", textfont8W, Element.ALIGN_CENTER, 1, 1));

					table1.addCell(PdfUtil.createCell("原产地", textfont8W, Element.ALIGN_CENTER, 1, 1, 1));
					table1.addCell(PdfUtil.createCell(originCountry, textfont8, Element.ALIGN_CENTER, 2, 2, 1));
					table1.addCell(PdfUtil.createCell("公司编码", textfont8W, Element.ALIGN_CENTER, 1, 1));
					table1.addCell(PdfUtil.createCell(vgsbm, textfont8, Element.ALIGN_CENTER, 2, 2, 1));
					table1.addCell(PdfUtil.createCell("country Of Origin", textfont8W, Element.ALIGN_CENTER, 1, 1, 1));
					table1.addCell(PdfUtil.createCell("Company Code", textfont8W, Element.ALIGN_CENTER, 1, 1));

					table1.addCell(PdfUtil.createCell("商品编码", textfont8W, Element.ALIGN_CENTER, 1, 1));
					table1.addCell(PdfUtil.createCell("品名描述", textfont8W, Element.ALIGN_CENTER, 1, 1));
					table1.addCell(PdfUtil.createCell("数量", textfont8W, Element.ALIGN_CENTER, 1, 1));
					table1.addCell(PdfUtil.createCell("单位", textfont8W, Element.ALIGN_CENTER, 1, 1));
					table1.addCell(PdfUtil.createCell("单价(CNY)", textfont8W, Element.ALIGN_CENTER, 1, 1));
					table1.addCell(PdfUtil.createCell("金额(CNY)", textfont8W, Element.ALIGN_CENTER, 1, 1));

					table1.addCell(PdfUtil.createCell("Product Code", textfont8W, Element.ALIGN_CENTER, 1, 1));
					table1.addCell(PdfUtil.createCell("Description", textfont8W, Element.ALIGN_CENTER, 1, 1));
					table1.addCell(PdfUtil.createCell("Qity", textfont8W, Element.ALIGN_CENTER, 1, 1));
					table1.addCell(PdfUtil.createCell("Company", textfont8W, Element.ALIGN_CENTER, 1, 1));
					table1.addCell(PdfUtil.createCell("Unit Price", textfont8W, Element.ALIGN_CENTER, 1, 1));
					table1.addCell(PdfUtil.createCell("Amount", textfont8W, Element.ALIGN_CENTER, 1, 1));

					for(ProductDto product : listData) {
						table1.addCell(PdfUtil.createCell(product.getProductCode(), textfont8, Element.ALIGN_CENTER, 1, 1));
						table1.addCell(PdfUtil.createCell(product.getDescription(), textfont8, Element.ALIGN_CENTER, 1, 1));
						table1.addCell(PdfUtil.createCell(product.getQity(), textfont8, Element.ALIGN_CENTER, 1, 1));
						table1.addCell(PdfUtil.createCell(product.getUnit(), textfont8, Element.ALIGN_CENTER, 1, 1));
						table1.addCell(PdfUtil.createCell(product.getUnitPrice(), textfont8, Element.ALIGN_CENTER, 1, 1));
						table1.addCell(PdfUtil.createCell(product.getTotalPrice(), textfont8, Element.ALIGN_CENTER, 1, 1));
					}
				}
				document.add(table1);

			}

			// 5.关闭文档
			document.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

		return MyConfig.getUrlDomain() + "/upload/pdf/" + code + ".pdf";
	}

	@Override
	public String generatePDF_FWFP(String companyAllNameCn, String companyAllNameEn, String toCompanyAllNameCn,
			String invoiceNo, String amountTotalCny, String invoiceDate, String originCountry, String vgsbm,
			List<SaleDto> listData) {

		String code = "FW_" + invoiceNo;


		Rectangle rec = new RectangleReadOnly(420, 600);

		try {
			// 1.新建document对象
			Document document = new Document(rec);// 建立一个Document对象
			document.setMargins(0, 0, 15f, 0);
			document.setPageCount(1);//设置生成pdf页数
			// 2.建立一个书写器(Writer)与document对象关联
//			File file = new File("D://data/PDF配货清单.pdf");
			String dir = MyConfig.getProfile();
			String pdfFileName = "/pdf/" + code + ".pdf";
			File file = new File(dir + pdfFileName);
			file.createNewFile();
			PdfWriter.getInstance(document, new FileOutputStream(file));
			// 3.打开文档
			document.open();

			//4.生成PDF
			document.newPage();
//			document.setPageCount(i);//设置生成pdf页数
			{

				// 表格
				PdfPTable table1;
				{
					table1 = PdfUtil.createTable(new float[]{100, 100, 100, 100, 100, 100}, 1, 400);

					table1.addCell(PdfUtil.createCell(companyAllNameCn, textfont14W, Element.ALIGN_CENTER, 6, 1));
					table1.addCell(PdfUtil.createCell(companyAllNameEn, textfont14, Element.ALIGN_CENTER, 6, 1));
					table1.addCell(PdfUtil.createCell("服务发票", textfont14W, Element.ALIGN_CENTER, 6, 1));
					table1.addCell(PdfUtil.createCell("Sales Invoice", textfont14, Element.ALIGN_CENTER, 6, 1));

					table1.addCell(PdfUtil.createCell("TO:", textfont8W, Element.ALIGN_CENTER, 1, 2, 1));
					table1.addCell(PdfUtil.createCell(toCompanyAllNameCn, textfont8, Element.ALIGN_CENTER, 2, 2, 1));
					table1.addCell(PdfUtil.createCell("发票号码", textfont8W, Element.ALIGN_CENTER, 1, 1));
					table1.addCell(PdfUtil.createCell(invoiceNo, textfont8, Element.ALIGN_CENTER, 2, 2, 1));
					table1.addCell(PdfUtil.createCell("Invoice No.", textfont8W, Element.ALIGN_CENTER, 1, 1));

					table1.addCell(PdfUtil.createCell("总金额(CNY)", textfont8W, Element.ALIGN_CENTER, 1, 1, 1));
					table1.addCell(PdfUtil.createCell(amountTotalCny, textfont8, Element.ALIGN_CENTER, 2, 2, 1));
					table1.addCell(PdfUtil.createCell("发票日期", textfont8W, Element.ALIGN_CENTER, 1, 1));
					table1.addCell(PdfUtil.createCell(invoiceDate, textfont8, Element.ALIGN_CENTER, 2, 2, 1));
					table1.addCell(PdfUtil.createCell("Total Amount", textfont8W, Element.ALIGN_CENTER, 1, 1, 1));
					table1.addCell(PdfUtil.createCell("Date of Invoice", textfont8W, Element.ALIGN_CENTER, 1, 1));

					table1.addCell(PdfUtil.createCell("原产地", textfont8W, Element.ALIGN_CENTER, 1, 1, 1));
					table1.addCell(PdfUtil.createCell(originCountry, textfont8, Element.ALIGN_CENTER, 2, 2, 1));
					table1.addCell(PdfUtil.createCell("公司编码", textfont8W, Element.ALIGN_CENTER, 1, 1));
					table1.addCell(PdfUtil.createCell(vgsbm, textfont8, Element.ALIGN_CENTER, 2, 2, 1));
					table1.addCell(PdfUtil.createCell("country Of Origin", textfont8W, Element.ALIGN_CENTER, 1, 1, 1));
					table1.addCell(PdfUtil.createCell("Company Code", textfont8W, Element.ALIGN_CENTER, 1, 1));

					table1.addCell(PdfUtil.createCell("服务及描述", textfont8W, Element.ALIGN_CENTER, 2, 1));
					table1.addCell(PdfUtil.createCell("数量", textfont8W, Element.ALIGN_CENTER, 1, 1));
					table1.addCell(PdfUtil.createCell("单位", textfont8W, Element.ALIGN_CENTER, 1, 1));
					table1.addCell(PdfUtil.createCell("单价(CNY)", textfont8W, Element.ALIGN_CENTER, 1, 1));
					table1.addCell(PdfUtil.createCell("金额(CNY)", textfont8W, Element.ALIGN_CENTER, 1, 1));

					table1.addCell(PdfUtil.createCell("Service and Description", textfont8W, Element.ALIGN_CENTER, 2, 1));
					table1.addCell(PdfUtil.createCell("Qity", textfont8W, Element.ALIGN_CENTER, 1, 1));
					table1.addCell(PdfUtil.createCell("Company", textfont8W, Element.ALIGN_CENTER, 1, 1));
					table1.addCell(PdfUtil.createCell("Unit Price", textfont8W, Element.ALIGN_CENTER, 1, 1));
					table1.addCell(PdfUtil.createCell("Amount", textfont8W, Element.ALIGN_CENTER, 1, 1));

					for(SaleDto product : listData) {
						table1.addCell(PdfUtil.createCell(product.getDescription(), textfont8, Element.ALIGN_CENTER, 2, 1));
						table1.addCell(PdfUtil.createCell(product.getQity(), textfont8, Element.ALIGN_CENTER, 1, 1));
						table1.addCell(PdfUtil.createCell(product.getUnit(), textfont8, Element.ALIGN_CENTER, 1, 1));
						table1.addCell(PdfUtil.createCell(product.getUnitPrice(), textfont8, Element.ALIGN_CENTER, 1, 1));
						table1.addCell(PdfUtil.createCell(product.getTotalPrice(), textfont8, Element.ALIGN_CENTER, 1, 1));
					}
				}
				document.add(table1);

			}

			// 5.关闭文档
			document.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

		return MyConfig.getUrlDomain() + "/upload/pdf/" + code + ".pdf";
	}

	@Override
	public String generateGoodsPDF_Listring(String productCode, String productName, String vgsbm, String vgsjc, List<ListingSubDto> listData) {

		Rectangle rec = new RectangleReadOnly(420, 300);

		try {
			// 1.新建document对象
			Document document = new Document(rec);// 建立一个Document对象
			document.setMargins(0, 0, 15f, 0);
			document.setPageCount(1);//设置生成pdf页数
			// 2.建立一个书写器(Writer)与document对象关联
//			File file = new File("D://data/PDF配货清单.pdf");
			String dir = MyConfig.getProfile();
			String pdfFileName = "/pdf/" + productCode + ".pdf";
			File file = new File(dir + pdfFileName);
			file.createNewFile();
			PdfWriter.getInstance(document, new FileOutputStream(file));
			// 3.打开文档
			document.open();

			//4.生成PDF
			document.newPage();
//			document.setPageCount(i);//设置生成pdf页数
			{

				// 表格
				PdfPTable table1;
				{
					table1 = PdfUtil.createTable(new float[]{130, 260}, 1, 390);

					table1.addCell(PdfUtil.createCell("公司编码", textfont14, Element.ALIGN_LEFT, 1, 0));
					table1.addCell(PdfUtil.createCell(vgsbm, textfont14, Element.ALIGN_LEFT, 1, 0));

					table1.addCell(PdfUtil.createCell("公司简称", textfont14, Element.ALIGN_LEFT, 1, 0));
					table1.addCell(PdfUtil.createCell(vgsjc, textfont14, Element.ALIGN_LEFT, 1, 0));

					table1.addCell(PdfUtil.createCell("商品信息", textfont14, Element.ALIGN_LEFT, 1, 0));
					table1.addCell(PdfUtil.createCell(productName, textfont14, Element.ALIGN_LEFT, 1, 0));

					table1.addCell(PdfUtil.createCell(" ", textfont4, Element.ALIGN_LEFT, 2, 0));
					table1.addCell(PdfUtil.createCell("货件清单", textfont14, Element.ALIGN_LEFT, 2, 0));

					table1.addCell(PdfUtil.createCell("商品编码", textfont8, Element.ALIGN_CENTER, 1, 1, 1));
					table1.addCell(PdfUtil.createCell("商品名称", textfont8, Element.ALIGN_CENTER, 1, 1));

					for(ListingSubDto product : listData) {
						table1.addCell(PdfUtil.createCell(product.getCode(), textfont14, Element.ALIGN_CENTER, 1, 1));
						table1.addCell(PdfUtil.createCell(product.getName(), textfont14, Element.ALIGN_CENTER, 1, 1));
					}
				}
				document.add(table1);

			}

			// 5.关闭文档
			document.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

		return MyConfig.getUrlDomain() + "/upload/pdf/" + productCode + ".pdf";
	}

	/**
	 * 欧代标打印预览
	 * @param bid
	 * @param dtoList
	 * @return
	 */
	@Override
	public String europeanStandardPrint(String bid, List<EuropeanStandardPrintDto> dtoList) {
			String code = "XS_" + bid;

			Rectangle rec = new RectangleReadOnly(500, 500);

			try {
				// 1.新建document对象
				Document document = new Document(rec);// 建立一个Document对象
				document.setMargins(0, 0, 15f, 0);
				document.setPageCount(1);//设置生成pdf页数
				// 2.建立一个书写器(Writer)与document对象关联
	//			File file = new File("D://data/PDF配货清单.pdf");
				String dir = MyConfig.getProfile();
				String pdfFileName = "/pdf/" + code + ".pdf";
				File file = new File(dir + pdfFileName);
				file.createNewFile();
				PdfWriter.getInstance(document, new FileOutputStream(file));
				// 3.打开文档
				document.open();

				for (int i = 0; i < dtoList.size(); i++) {
					//4.生成PDF
					generateEuropeanStandard(document, dtoList.get(i));
				}

				// 5.关闭文档
				document.close();
			} catch (Exception e) {
				e.printStackTrace();
			}

			return MyConfig.getUrlDomain() + "/upload/pdf/" + code + ".pdf";
	}

	// 生成欧代标PDF
	public void generateEuropeanStandard(Document document, EuropeanStandardPrintDto dto) throws Exception {
		document.newPage();
		// 表格
		PdfPTable table2;
		{
			table2 = PdfUtil.createTable(new float[]{200, 280}, 1, 480);

			table2.addCell(createCellHeight("Description of Product:", textfont16Bold, Element.ALIGN_CENTER, 1,30f));
			table2.addCell(createCellHeight(dto.getDescriptionProduct(), textfont16, Element.ALIGN_CENTER, 1,30f));
			table2.addCell(createCellHeight("Model：", textfont16Bold, Element.ALIGN_CENTER, 1,30f));
			table2.addCell(createCellHeight(dto.getModel(), textfont16, Element.ALIGN_CENTER, 1,30f));
			table2.addCell(createCellHeight("EU Agent：", textfont16Bold, Element.ALIGN_CENTER, 1,30f));
			table2.addCell(createCellHeight(dto.getEuAgent(), textfont16, Element.ALIGN_CENTER, 1,30f));
			table2.addCell(createCellHeight("EU agent address：", textfont16Bold, Element.ALIGN_CENTER, 1,30f));
			table2.addCell(createCellHeight(dto.getEuAgentAddress(), textfont16, Element.ALIGN_CENTER, 1,30f));
			table2.addCell(createCellHeight("Manufacturer ：", textfont16Bold, Element.ALIGN_CENTER, 1,30f));
			table2.addCell(createCellHeight(dto.getManufacturer(), textfont16, Element.ALIGN_CENTER, 1,30f));
			table2.addCell(createCellHeight("Manufacturer Address ：", textfont16Bold, Element.ALIGN_CENTER, 1,30f));
			table2.addCell(createCellHeight(dto.getManufactureraddress(), textfont16, Element.ALIGN_CENTER, 1,30f));
			table2.addCell(createCellHeight("Age Range:", textfont16Bold, Element.ALIGN_CENTER, 1,30f));
			table2.addCell(createCellHeight(dto.getAgeRange(), textfont16, Element.ALIGN_CENTER, 1,30f));
			table2.addCell(createCellHeight("Production Date:", textfont16Bold, Element.ALIGN_CENTER, 1,30f));
			table2.addCell(createCellHeight(dto.getProductionDate(), textfont16, Element.ALIGN_CENTER, 1,30f));
		}

		// 空白表格
		PdfPTable tableBlank = createBlankTable(15.0f);

		// 表格
		PdfPTable table1;
		table1 = PdfUtil.createTable(new float[]{240,240}, 0, 480);
		table1.addCell(PdfUtil.createCell("MADE IN CHINA", textfont16Bold, Element.ALIGN_CENTER, 0));
		table1.addCell(createPdfCell("https://file.mini-ease.com/upload/nomodule/202410/09/211333666.png"));

		List<PdfPTable> pdfPTableList = new ArrayList<>();
		int size = dto.getTbFileInfos().size();
		double num = Math.ceil(size/5.0);
		int k = 0;
		float[] dynamicArray = new float[5];
		dynamicArray[0] = 96;
		dynamicArray[1] = 96;
		dynamicArray[2] = 96;
		dynamicArray[3] = 96;
		dynamicArray[4] = 96;
		for (int i = 0; i < num; i++) {
			PdfPTable table3 =  PdfUtil.createTable(dynamicArray, 0, 480);
			for (int j = 0; j < 5; j++) {
				if (dto.getTbFileInfos().size()-1 >= k ){
					table3.addCell(createPdfCell(dto.getTbFileInfos().get(k).getFilePath()));
				}else {
					table3.addCell(createBlankCell());
				}
				k = k + 1;
			}
			pdfPTableList.add(table3);
		}


		for (int i = 0; i < dto.getNumPlanDeliver(); i++) {
			document.newPage();
			document.add(table2);
			document.add(tableBlank);
			document.add(table1);
			for (PdfPTable pdfPTable : pdfPTableList){
				document.add(pdfPTable);
			}
		}
	}

	/**
	 * 自定义打印模版（财务使用）
	 * @param bid
	 * @param title
	 * @param companyVname
	 * @param timeYYYYMMDDHHmmss
	 * @param listData
	 * @return
	 */
	@Override
	public String generateZLY(String bid, String title, String companyVname, String timeYYYYMMDDHHmmss, List<NameValueDto> listData,List<Map<String, Object>>  auditDataList,
							  String printTime,String printUser,String printDep) {

		Rectangle rec = new RectangleReadOnly(420, 600);
		try {
			// 1.新建document对象
			Document document = new Document(rec);// 建立一个Document对象
			document.setMargins(0, 0, 15f, 0);
			document.setPageCount(1);//设置生成pdf页数
			// 2.建立一个书写器(Writer)与document对象关联
//			File file = new File("D://data/PDF配货清单.pdf");
			String dir = MyConfig.getProfile();
			String pdfFileName = "/pdf/" + bid + ".pdf";
			File file = new File(dir + pdfFileName);
			file.createNewFile();
			PdfWriter.getInstance(document, new FileOutputStream(file));
			// 3.打开文档
			document.open();

			//4.生成PDF
			document.newPage();
//			document.setPageCount(i);//设置生成pdf页数
			{// 表格
				PdfPTable table1;
				PdfPTable table2;
				{
					table1 = PdfUtil.createTable(new float[]{80, 60, 100, 60}, 1, 400);
					table2 = PdfUtil.createTable(new float[]{134, 133, 133}, 1, 400);

					table1.addCell(PdfUtil.createCell(title, textfont14, Element.ALIGN_CENTER, 4, 0));
					table1.addCell(PdfUtil.createCell(companyVname, textfont8, Element.ALIGN_LEFT, 2, 0));
					table1.addCell(PdfUtil.createCell("申请时间：" + timeYYYYMMDDHHmmss, textfont8, Element.ALIGN_RIGHT, 2, 0));

					for(NameValueDto e : listData) {
						table1.addCell(PdfUtil.createCell(e.getName() + "：", textfont8, Element.ALIGN_CENTER, 1));
						table1.addCell(PdfUtil.createCell(e.getValue(), textfont8, Element.ALIGN_CENTER, 4, 1));
					}

					table1.addCell(PdfUtil.createCell("审核明细", textfont8, Element.ALIGN_LEFT, 5, 0));
					{

						table2.addCell(PdfUtil.createCell("处理时间", textfont8, Element.ALIGN_CENTER, 1));
						table2.addCell(PdfUtil.createCell("处理人", textfont8, Element.ALIGN_CENTER, 1));
						table2.addCell(PdfUtil.createCell("处理结果", textfont8, Element.ALIGN_CENTER, 1));
					}

					for(Map<String, Object> auditData: auditDataList) {


						table2.addCell(PdfUtil.createCell(auditData.get("processingTime").toString(), textfont8, Element.ALIGN_CENTER, 1));
						table2.addCell(PdfUtil.createCell(auditData.get("processingUser").toString(), textfont8, Element.ALIGN_CENTER, 1));
						table2.addCell(PdfUtil.createCell(auditData.get("processingResult").toString(), textfont8, Element.ALIGN_CENTER, 1));
					}

					{
						table2.addCell(PdfUtil.createCell(printTime, textfont8, Element.ALIGN_CENTER, 0));
						table2.addCell(PdfUtil.createCell(printUser, textfont8, Element.ALIGN_CENTER, 0));
						table2.addCell(PdfUtil.createCell(printDep, textfont8, Element.ALIGN_CENTER,  0));
					}
				}
				document.add(table1);
				document.add(table2);

			}

			// 5.关闭文档
			document.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

		return MyConfig.getUrlDomain() + "/upload/pdf/" + bid + ".pdf";
	}

	/**
	 * 打印入库箱标
	 * @param stockInDtoList
	 * @return
	 */
	@Override
	public String generateGoodsPDF_RKXB(List<TccOfflineAssembleImpl.StockInDto> stockInDtoList) {
		Rectangle rec = new RectangleReadOnly(500, 500);
		long date = new Date().getTime();

		try {
			// 1.新建document对象
			Document document = new Document(rec);// 建立一个Document对象
			document.setMargins(0, 0, 15f, 0);
			document.setPageCount(1);//设置生成pdf页数
			// 2.建立一个书写器(Writer)与document对象关联
			String dir = MyConfig.getProfile();
			String pdfFileName = "/pdf/" + date + ".pdf";
			File file = new File(dir + pdfFileName);
			file.createNewFile();
			PdfWriter.getInstance(document, new FileOutputStream(file));
			// 3.打开文档
			document.open();

			for (TccOfflineAssembleImpl.StockInDto stockInDto : stockInDtoList){
				//4.生成PDF第一页
				generateStockIn1(document, stockInDto);
				//4.生成PDF第二页
				generateStockIn2(document, stockInDto);
			}
			// 5.关闭文档
			document.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

		return MyConfig.getUrlDomain() + "/upload/pdf/" + date + ".pdf";
	}

	@Override
	public String generateGoodsPDF_ZZQD(TccOfflineAssembleImpl.ZuzhuangDto zuzhuangDto) {
		Rectangle rec = new RectangleReadOnly(800, 500);
		long date = new Date().getTime();

		try {
			// 1.新建document对象
			Document document = new Document(rec);// 建立一个Document对象
			document.setMargins(0, 0, 15f, 0);
			document.setPageCount(1);//设置生成pdf页数
			// 2.建立一个书写器(Writer)与document对象关联
			String dir = MyConfig.getProfile();
			String pdfFileName = "/pdf/" + date + ".pdf";
			File file = new File(dir + pdfFileName);
			file.createNewFile();
			PdfWriter.getInstance(document, new FileOutputStream(file));
			// 3.打开文档
			document.open();

			// 表格
			PdfPTable table;
			{
				table = PdfUtil.createTable(new float[]{70, 30, 30, 50,80, 50, 30, 70, 70,50, 50,30, 30, 30 ,30,30}, 1, 770);

				// 第一行需要跨列数量
				table.addCell(PdfUtil.createCell("组装清单("+ zuzhuangDto.getAssemblyListBid()+")", textfont14, Element.ALIGN_LEFT, 18, 0));

				table.addCell(PdfUtil.createCell("组装单号", textfont12, Element.ALIGN_CENTER, 1));
				table.addCell(PdfUtil.createCell("公司编码", textfont12, Element.ALIGN_CENTER, 1));
				table.addCell(PdfUtil.createCell("公司简称", textfont12, Element.ALIGN_CENTER, 1));
				table.addCell(PdfUtil.createCell("母件编码", textfont12, Element.ALIGN_CENTER, 1));
				table.addCell(PdfUtil.createCell("母件名称", textfont12, Element.ALIGN_CENTER, 1));
				table.addCell(PdfUtil.createCell("母件尺寸", textfont12, Element.ALIGN_CENTER, 1));
				table.addCell(PdfUtil.createCell("采购数量", textfont12, Element.ALIGN_CENTER, 1));
				table.addCell(PdfUtil.createCell("采购订单", textfont12, Element.ALIGN_CENTER, 1));
				table.addCell(PdfUtil.createCell("物流运单号", textfont12, Element.ALIGN_CENTER, 1));
				table.addCell(PdfUtil.createCell("子件编码", textfont12, Element.ALIGN_CENTER, 1));
				table.addCell(PdfUtil.createCell("子件名称", textfont12, Element.ALIGN_CENTER, 1));
				table.addCell(PdfUtil.createCell("加购数量", textfont12, Element.ALIGN_CENTER, 1));
				table.addCell(PdfUtil.createCell("采购总数", textfont12, Element.ALIGN_CENTER, 1));
				table.addCell(PdfUtil.createCell("货位", textfont12, Element.ALIGN_CENTER, 1));
				table.addCell(PdfUtil.createCell("实际数量", textfont12, Element.ALIGN_CENTER, 1));
				table.addCell(PdfUtil.createCell("剩余数量", textfont12, Element.ALIGN_CENTER, 1));


				for (TccOfflineAssembleImpl.ZuzhuangDto.RowDto rows : zuzhuangDto.getRows()) {
					for (int i = 0; i < rows.getBoms().size(); i++) {
						if(i == 0){
							table.addCell(PdfUtil.createCell1(rows.getBid(), textfont10, Element.ALIGN_CENTER, 1,rows.getBoms().size()));
							table.addCell(PdfUtil.createCell1(rows.getVgsbm(), textfont10, Element.ALIGN_CENTER, 1,rows.getBoms().size()));
							table.addCell(PdfUtil.createCell1(rows.getVgsjc(), textfont10, Element.ALIGN_CENTER, 1,rows.getBoms().size()));
							table.addCell(PdfUtil.createCell1(rows.getProductCode(), textfont10, Element.ALIGN_CENTER, 1,rows.getBoms().size()));
							table.addCell(PdfUtil.createCell1(rows.getProductName(), textfont10, Element.ALIGN_CENTER, 1,rows.getBoms().size()));
							table.addCell(PdfUtil.createCell1(rows.getSize(), textfont10, Element.ALIGN_CENTER, 1,rows.getBoms().size()));
							table.addCell(PdfUtil.createCell1(rows.getSubPlanStorageNum(), textfont10, Element.ALIGN_CENTER, 1,rows.getBoms().size()));
						}
					}
					for (TccOfflineAssembleImpl.ZuzhuangDto.RowDto.BomDto bomDto : rows.getBoms()) {
						table.addCell(PdfUtil.createCell(bomDto.getPurchaseOrderBid(), textfont10, Element.ALIGN_CENTER, 1));
						table.addCell(PdfUtil.createCell(bomDto.getAliLogisticsBillNo(), textfont10, Element.ALIGN_CENTER, 1));
						table.addCell(PdfUtil.createCell(bomDto.getSubCode(), textfont10, Element.ALIGN_CENTER, 1));
						table.addCell(PdfUtil.createCell(bomDto.getSubName(), textfont10, Element.ALIGN_CENTER, 1));
						table.addCell(PdfUtil.createCell(bomDto.getJgSl(), textfont10, Element.ALIGN_CENTER, 1));
						table.addCell(PdfUtil.createCell(bomDto.getSubTotalAmount(), textfont10, Element.ALIGN_CENTER, 1));
						table.addCell(PdfUtil.createCell(bomDto.getVhw(), textfont10, Element.ALIGN_CENTER, 1));
						table.addCell(PdfUtil.createCell("", textfont10, Element.ALIGN_CENTER, 1));
						table.addCell(PdfUtil.createCell("", textfont10, Element.ALIGN_CENTER, 1));
					}
				}
			}
			document.add(table);
			// 5.关闭文档
			document.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return MyConfig.getUrlDomain() + "/upload/pdf/" + date + ".pdf";
	}

	// 生成采购入库单PDF
	public void generateStockIn1(Document document, TccOfflineAssembleImpl.StockInDto dto) throws Exception {
		document.newPage();
		// 表格
		PdfPTable table1;
		{
			table1 = PdfUtil.createTable(new float[]{500}, 1, 500);

			table1.addCell(PdfUtil.createCell("采购订单:" + dto.getCodeCgdd(), textfont16Bold, Element.ALIGN_CENTER, 0));
			table1.addCell(PdfUtil.createCell("物流运单号:" + dto.getAliLogisticsBillNo(), textfont16Bold, Element.ALIGN_CENTER, 0));
		}
		document.add(table1);
		Image image = Image.getInstance(dto.getImg());
		image.setAlignment(Image.ALIGN_CENTER);
		image.setAlignment(Image.ALIGN_MIDDLE);
		image.scaleAbsolute(300,300); //依照比例缩放
		image.setSpacingBefore(0f);
		image.setBottom(0f);
		document.add(image);
	}

	// 生成采购入库单PDF
	public void generateStockIn2(Document document, TccOfflineAssembleImpl.StockInDto dto) throws Exception {
		document.newPage();

		// 表格
		PdfPTable table1;
		{
			table1 = PdfUtil.createTable(new float[]{160, 320}, 0, 480);

			table1.addCell(PdfUtil.createCell("采购订单：", textfont18, Element.ALIGN_LEFT, 0));
			table1.addCell(PdfUtil.createCell(dto.getCodeCgdd(), textfont18, Element.ALIGN_LEFT, 0));

			table1.addCell(PdfUtil.createCell("物流运单号：", textfont18, Element.ALIGN_LEFT, 0));
			table1.addCell(PdfUtil.createCell(dto.getAliLogisticsBillNo(), textfont18, Element.ALIGN_LEFT, 0));

			table1.addCell(PdfUtil.createCell("公司编码：", textfont18, Element.ALIGN_LEFT, 0));
			table1.addCell(PdfUtil.createCell(dto.getCodeCompany(), textfont18, Element.ALIGN_LEFT, 0));

			table1.addCell(PdfUtil.createCell("公司简称：", textfont18, Element.ALIGN_LEFT, 0));
			table1.addCell(PdfUtil.createCell(dto.getNameCompany(), textfont18, Element.ALIGN_LEFT, 0));

			table1.addCell(PdfUtil.createCell("商品信息：", textfont18, Element.ALIGN_LEFT, 0));
			table1.addCell(PdfUtil.createCell(dto.getInfoGoods(), textfont18, Element.ALIGN_LEFT, 0));

			table1.addCell(PdfUtil.createCell("组装数量：", textfont18, Element.ALIGN_LEFT, 0));
			table1.addCell(PdfUtil.createCell(dto.getSpAmount(), textfont18, Element.ALIGN_LEFT, 0));

			table1.addCell(PdfUtil.createCell("组装材料：", textfont18, Element.ALIGN_LEFT, 0));
			table1.addCell(PdfUtil.createCell(dto.getAssembleSign(), textfont18, Element.ALIGN_LEFT, 0));
		}

		// 空白表格
		PdfPTable tableBlank = createBlankTable(5.0f);

		// 表格2
		PdfPTable table2;
		{
			table2 = PdfUtil.createTable(new float[]{96,96,96,96,96}, 1, 480);

			table2.addCell(PdfUtil.createCell("采购清单", textfont18, Element.ALIGN_LEFT, 5, 0));

			table2.addCell(PdfUtil.createCell("商品编码", textfont16, Element.ALIGN_CENTER, 1));
			table2.addCell(PdfUtil.createCell("商品名称", textfont16, Element.ALIGN_CENTER, 1));
			table2.addCell(PdfUtil.createCell("采购数量", textfont16, Element.ALIGN_CENTER, 1));
			table2.addCell(PdfUtil.createCell("加购数量", textfont16, Element.ALIGN_CENTER, 1));
			table2.addCell(PdfUtil.createCell("采购总数", textfont16, Element.ALIGN_CENTER, 1));

			for(TccOfflineAssembleImpl.StockInDto.RowDto row : dto.getRows()) {
				table2.addCell(PdfUtil.createCell(row.getSubCode(), textfont16, Element.ALIGN_LEFT, 1));
				table2.addCell(PdfUtil.createCell(row.getSubName(), textfont16, Element.ALIGN_LEFT, 1));
				table2.addCell(PdfUtil.createCell(row.getPurchaseAmount(), textfont16, Element.ALIGN_CENTER, 1));
				table2.addCell(PdfUtil.createCell(row.getJgSl(), textfont16, Element.ALIGN_CENTER, 1));
				table2.addCell(PdfUtil.createCell(row.getSubTotalAmount(), textfont16, Element.ALIGN_CENTER, 1));
			}

		}

		// 表格3
		PdfPTable table3;
		{
			table3 = PdfUtil.createTable(new float[]{140, 240, 100}, 1, 480);

			table3.addCell(PdfUtil.createCell("组装BOM", textfont18, Element.ALIGN_LEFT, 3, 0));

			table3.addCell(PdfUtil.createCell("子件编码", textfont16, Element.ALIGN_CENTER, 1));
			table3.addCell(PdfUtil.createCell("子件名称", textfont16, Element.ALIGN_CENTER, 1));
			table3.addCell(PdfUtil.createCell("子件数量", textfont16, Element.ALIGN_CENTER, 1));

			for(TccOfflineAssembleImpl.StockInDto.BomDto bom : dto.getBoms()) {
				table3.addCell(PdfUtil.createCell(bom.getCodeGoods(), textfont16, Element.ALIGN_LEFT, 1));
				table3.addCell(PdfUtil.createCell(bom.getNameGoods(), textfont16, Element.ALIGN_LEFT, 1));
				table3.addCell(PdfUtil.createCell(bom.getNum(), textfont16, Element.ALIGN_CENTER, 1));
			}

		}
		document.add(table1);
		document.add(tableBlank);
		document.add(table2);
		document.add(tableBlank);
		document.add(table3);
	}
	/**
	 * 打印箱标其他信息
	 * @return
	 */
	@Override
	public String getLabelsPDF(String getFbaNo,String vgsbm,String logsticsWay,String boxWeight,String boxNo) {

		Rectangle rec = new RectangleReadOnly(420, 300);
				try {
					// 1.新建document对象
					Document document = new Document(rec);// 建立一个Document对象
					document.setMargins(0, 0, 15f, 0);
					document.setPageCount(1);//设置生成pdf页数
					// 2.建立一个书写器(Writer)与document对象关联
//			File file = new File("D://data/PDF配货清单.pdf");
					String dir = MyConfig.getProfile();
//					String dir = "D://data";
					String pdfFileName = "/pdf/" + getFbaNo + ".pdf";
					File file = new File(dir + pdfFileName);
					file.createNewFile();
					PdfWriter.getInstance(document, new FileOutputStream(file));
					// 3.打开文档
					document.open();

					//4.生成PDF
					document.newPage();
//			document.setPageCount(i);//设置生成pdf页数
					{
						// 表格
						PdfPTable table1;
						{
							table1 = PdfUtil.createTable(new float[]{60, 120, 200}, 0, 380);

							table1.addCell(PdfUtil.createCell("运营公司简称：", textfont8, Element.ALIGN_LEFT, 0));
							table1.addCell(PdfUtil.createCell(vgsbm, textfont8, Element.ALIGN_LEFT, 1, 0));
							table1.addCell(PdfUtil.createCell("", textfont8, Element.ALIGN_LEFT, 0));

							table1.addCell(PdfUtil.createCell("物流服务：", textfont8, Element.ALIGN_LEFT, 0));
							table1.addCell(PdfUtil.createCell(logsticsWay, textfont8, Element.ALIGN_LEFT, 1, 0));
							table1.addCell(PdfUtil.createCell("", textfont8, Element.ALIGN_LEFT, 0));

							table1.addCell(PdfUtil.createCell("箱重：", textfont8, Element.ALIGN_LEFT, 0));
							table1.addCell(PdfUtil.createCell(boxWeight, textfont8, Element.ALIGN_LEFT, 1, 0));
							table1.addCell(PdfUtil.createCell("", textfont8, Element.ALIGN_LEFT, 0));

							table1.addCell(PdfUtil.createCell("FBA编号：", textfont8, Element.ALIGN_LEFT, 0));
							table1.addCell(PdfUtil.createCell(getFbaNo, textfont8, Element.ALIGN_LEFT, 1, 0));
							table1.addCell(PdfUtil.createCell("", textfont8, Element.ALIGN_LEFT, 0));

							table1.addCell(PdfUtil.createCell("箱号：", textfont8, Element.ALIGN_LEFT, 0));
							table1.addCell(PdfUtil.createCell(boxNo, textfont8, Element.ALIGN_LEFT, 1, 0));
							table1.addCell(PdfUtil.createCell("", textfont8, Element.ALIGN_LEFT, 0));
						}
						document.add(table1);

					}// 5.关闭文档
					document.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			return MyConfig.getUrlDomain() + "/upload/pdf/" + getFbaNo + ".pdf";
	}

	/**
	 * 打印箱标其他信息
	 * @return
	 */
	@Override
	public String getUrlFba(String spOrderBids,String packno) {

		Rectangle rec = new RectangleReadOnly(420, 300);
		try {
			// 1.新建document对象
			Document document = new Document(rec);// 建立一个Document对象
			document.setMargins(0, 0, 15f, 0);
			document.setPageCount(1);//设置生成pdf页数
			// 2.建立一个书写器(Writer)与document对象关联
//			File file = new File("D://data/PDF配货清单.pdf");
			String dir = MyConfig.getProfile();
//			String dir = "D://data";
			String pdfFileName = "/pdf/" + packno + ".pdf";
			File file = new File(dir + pdfFileName);
			file.createNewFile();
			PdfWriter.getInstance(document, new FileOutputStream(file));
			// 3.打开文档
			document.open();

			//4.生成PDF
			document.newPage();
//			document.setPageCount(i);//设置生成pdf页数
			{
				// 表格
				PdfPTable table1;
				{
					table1 = PdfUtil.createTable(new float[]{100, 280}, 0, 380);

					table1.addCell(PdfUtil.createCell("发票号：", textfont16, Element.ALIGN_LEFT, 0));
					table1.addCell(PdfUtil.createCell(packno, textfont16, Element.ALIGN_LEFT, 1, 0));

					table1.addCell(PdfUtil.createCell("FBA编号：", textfont16, Element.ALIGN_LEFT, 0));
					table1.addCell(PdfUtil.createCell(spOrderBids, textfont16, Element.ALIGN_LEFT, 1, 0));

				}
				document.add(table1);

			}// 5.关闭文档
			document.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return MyConfig.getUrlDomain() + "/upload/pdf/" + packno + ".pdf";
	}

	/**
	 * 创建单元格（指定字体、水平..）
	 */
	public static PdfPCell createCellHeight(String value, Font font, int align, Integer border, float minimumHeight) {
		PdfPCell cell = new PdfPCell();
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cell.setHorizontalAlignment(align);
		cell.setMinimumHeight(minimumHeight);
		cell.setPhrase(new Phrase(value, font));
		cell.setBorder(border);
		if (border > 0) {
			cell = handelBorder(cell, 0.1f);
		} else {
			cell.disableBorderSide(15);//全部隐藏
		}
		return cell;
	}


	public static PdfPCell handelBorder(PdfPCell cell, float borderWidth) {
		cell.setBorder(0);
		cell.setBorderWidthTop(borderWidth);
		cell.setBorderWidthBottom(borderWidth);
		cell.setBorderWidthLeft(borderWidth);
		cell.setBorderWidthRight(borderWidth);
		cell.setBorderColorBottom(BaseColor.BLACK);
		cell.setBorderColorLeft(BaseColor.BLACK);
		cell.setBorderColorRight(BaseColor.BLACK);
		cell.setBorderColorTop(BaseColor.BLACK);
		return cell;
	}

	/**
	 * 创建指定的图片格式
	 */
	public static PdfPCell createPdfCell(String path) {
		PdfPCell acell = null;
		try {
			Image image1 = Image.getInstance(path);
			image1.setAlignment(Image.ALIGN_CENTER);
			// 缩放图像到30%的大小
			image1.scalePercent(5);
			acell = new PdfPCell(image1,false);
			acell.setVerticalAlignment(Element.ALIGN_MIDDLE);
			acell.setHorizontalAlignment(Element.ALIGN_CENTER);
			acell.setBorder(0);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return acell;
	}

	/**
	 * 创建空白的行
	 */
	public PdfPCell createBlankCell() {
		PdfPCell acell = new PdfPCell();
		acell.setBorder(0);
		return acell;
	}

	/**
	 * 创建空白的表格
	 */
	public PdfPTable createBlankTable(float spacing) {
		PdfPTable table = new PdfPTable(1);
		table.getDefaultCell().setBorder(0);
		table.addCell(PdfUtil.createCell("", keyfont, 0));
		table.setSpacingAfter(spacing);
		table.setSpacingBefore(spacing);
		return table;
	}
}
